package com.example.service.impl;

import com.example.dao.AttendanceDao;
import com.example.dao.UserDao;
import com.example.po.Attendance;
import com.example.service.AttendanceService;
import com.example.utils.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class AttendanceServiceImpl implements AttendanceService {
    @Autowired
    private AttendanceDao attendanceDao;
    @Override
    public boolean insertAttendance(Attendance attendance) {
        if(attendanceDao.insertAttendance(attendance)>=1){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public List<Attendance> searchAttendance(Attendance attendance, HttpSession session) {
        Page page= (Page) session.getAttribute("page");
        if(page==null){
            page=new Page();
            page.setCount(10);
            page.setStart(1);
            page.setTotal(attendanceDao.searchAttendances(attendance));
        }
        session.setAttribute("page",page);
        PageHelper.startPage(page.getStart(),page.getCount());
        List <Attendance> attendances=attendanceDao.searchAttendance(attendance);
        return attendances;
    }
    @Override
    public List<Attendance> search(Attendance attendance) {
        return attendanceDao.search(attendance);
    }

    @Override
    public boolean updateAttendance(Attendance attendance) {
        if(attendanceDao.updateAttendance(attendance)>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean deleteAttendance(int id) {
        if(attendanceDao.deleteAttendance(id)>0)
            return true;
        else
            return false;
    }
    @Override
    public List<Attendance> findAttendances(Attendance attendance) {
        List<Attendance> attendances= attendanceDao.findAttendances(attendance);
        return attendances;
    }
}
